<?php
class CatalogController extends DefaultController{
	
	protected $catalog;
	protected $childNote;
	
	public function _default(){
		$id = request('id');
		
		if (!$id) {
			$this->error('栏目ID未指定', '/');
		}
		
		$catalog = CatalogModel::get($id);
		
		if (!$catalog) {
			$this->error('栏目不存在', '/');
		}
		
		$this->catalog = $catalog;
		
		$location = $this->_location($id);
		
		$topId = $location[0]['id'];
		
		$childNote = $this->_childNote($topId);
		$this->assign('location', $location);
		$this->assign('subCatalog', $childNote);
		$this->childNote = $childNote;
		
		
		$func = '_' . $catalog['type'];
		
		$this->$func();
		
		$tpl = 'catalog_' . $catalog['type'];
		$this->assign('catalog', $this->catalog);
		$this->display($tpl);
	}
	
	private function _list(){
		$whereArr[] = "`catalog_id`='{$this->catalog['id']}'";
		$whereArr[] = "`status`='normal'";
		$where = implode(' and ', $whereArr);
		$page = $this->page(ArchiveModel::getCount($where));
		$archives = ArchiveModel::getList($where, $this->start, $this->perpage);
		$archives = $this->_formatArchive($archives);
		$this->assign('archives', $archives);
		$this->assign('page', $page);
		
	}
	
	private function _page(){
		
	}
	
	private function _channel(){
		$subIds = array_keys($this->childNote);
		
		$where = "`status`='normal' and `catalog_id` in (".implode(',', $subIds).")";
		$archives = ArchiveModel::catalogTop($where, 9);
		
		$archives = $this->_formatArchive($archives);
		
		$this->assign('channelArchives', $archives);
	}
	
	private function _link(){
		
	}
	
}